package kodkod.analysis.AST;

import kodkod.ast.*;

public class GraphVisitorDOT2 extends GraphVisitor {
	
	wGraph graph;
		
	public GraphVisitorDOT2(wGraph graph) {
		this.graph = graph;
	}
	
	protected String[] colors = {"black", "red", "blue", "red4", "blue4"}; 
	
	@Override
	protected void newEdge(Node parent, Node child, int pos) {
		wNode wParent = graph.getNode(parent);
		wNode wChild = graph.getNode(child);
		
		wChild.negated = negated;
				
		wEdge edge = graph.newEdge(wParent, wChild);
		if (pos > 0 && pos < colors.length) {
			edge.color = colors[pos];
		}
		
		if (currentPath.size() == 1) {
			graph.root = graph.getNode(parent);
		}
	}
	
	@Override
	protected void newEdge(Node parent, Node child) {
		newEdge(parent, child, 0);
	}
	
	@Override
	protected void newCompound(Node parent, Node child) {
		wCompoundNode wParent = graph.getCompoundNode(parent);
		wNode wChild = graph.getNode(child);
		wParent.addMember(wChild);
	}
	
	@Override
	protected void newNode(Node node) {}

	@Override
	public void visit(Relation relation) {
		enter(relation);
		graph.leafNodes.add(graph.getNode(relation));
		leave(relation);
	}

	@Override
	public void visit(Variable variable) {
		enter(variable);
		graph.leafNodes.add(graph.getNode(variable));
		leave(variable);
	}

	@Override
	public void visit(ConstantExpression constExpr) {
		enter(constExpr);
		graph.leafNodes.add(graph.getNode(constExpr));
		leave(constExpr);
	}

	@Override
	protected boolean visited(Node n) {
		// TODO Auto-generated method stub
		return false;
	}
}